package com.aaa.car.controller;

import com.aaa.car.service.ShopService;
import com.aaa.common.entity.Shop;
import com.github.pagehelper.PageInfo;
import com.aaa.common.util.Result;
import com.aaa.common.util.ResultStatus;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * (Shop)表控制层
 *
 * @author lei chu
 * @since 2021-01-23 09:13:38
 */
@RestController
@RequestMapping("shop")
@ApiOperation("shop控制器")
public class ShopController {
    /**
     * 服务对象
     */
    @Resource
    private ShopService shopService;

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("query/{id}")
    public Result<Shop> selectOne(@PathVariable("id") Integer id) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.shopService.queryById(id));
    }

    /**
     * 通过实体作为筛选条件查询
     *
     * @param pageNum  当前页数
     * @param pageSize 每页条数
     * @param shop     实例对象
     * @return 分页数据和信息
     */
    @PostMapping("queryAll")
    public Result<PageInfo<Shop>> queryAll(Integer pageNum, Integer pageSize, @RequestBody Shop shop) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.shopService.queryAll(pageNum, pageSize, shop));
    }

    /**
     * 新增数据
     *
     * @param shop 实例对象
     * @return 实例对象
     */
    @PostMapping("insert")
    public Result<Shop> insert(@RequestBody Shop shop) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.shopService.insert(shop));
    }

    /**
     * 修改数据
     *
     * @param shop 实例对象
     * @return 实例对象
     */
    @PutMapping("update")
    public Result<Shop> update(@RequestBody Shop shop) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.shopService.update(shop));
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @DeleteMapping("delete/{id}")
    public Result<Boolean> deleteById(@PathVariable("id") Integer id) {
        return new Result<>(ResultStatus.SUCCESS.getCode(),
                ResultStatus.SUCCESS.getMessage(),
                this.shopService.deleteById(id));
    }
}